{extend name="layout" /}
{block name="content"}
<div class="row">
  <div class="col-xs-8">
    <form id="searchForm">
      <div class="seardiv" style="width: 20%;float: left;">
        <select name="status" class="form-control input-sm">
          <option value="-1">状态</option>
          <option value="1">已回复</option>
          <option value="0">未回复</option>
        </select>
      </div>
      <div class="seardiv" style="width: 20%;float: left;">
        <select name="dealerid" class="form-control input-sm">
          <option value="">请选择经销商</option>
          {volist name="deallist" id="v"}
            <option value="{$key}">{$v}</option>
          {/volist}
        </select>
      </div>
      <div class="seardiv" style="width: 20%;float: left;">
        <input class="form-control input-sm" placeholder="请选择开始时间" type="text" name="startdate" id="startdate" AUTOCOMPLETE="off" value="">
      </div>
      <div class="seardiv" style="width: 20%;float: left;">
        <input class="form-control input-sm" placeholder="请选择结束时间" type="text" name="enddate" id="enddate" AUTOCOMPLETE="off" value="">
      </div>
      <div class="input-group input-group-sm demoTable">
        <input type="text" class="form-control input-sm" name="keywords" id="demoReload" autocomplete="off" placeholder="请输入申诉内容或回复内容">
        <span class="input-group-btn">
          <button type="button" class="btn btn-info btn-flat layui-btn" data-type="reload">搜  索</button>
        </span>
      </div>
    </form>
  </div>
  <div class="col-xs-4" style="text-align: right">
    <button type="button" class="btn btn-info btn-sm export" title="申诉表"><i class="fa fa-edit"></i> 数据导出</button>
  </div>
</div>
<table class="layui-table" lay-data="{height: 'full-75', cellMinWidth: 80, page: true, id:'lists',limit:30, url:'{:url('data_show_where',['order'=>'desc'])}'}" lay-filter="lists">
  <thead>
    <tr class="layui-colla-content">
         <th lay-data="{type:'checkbox'}">ID</th>
          <th lay-data="{field:'id', sort: true}">ID</th>
          <th lay-data="{field:'realname'}">经纪人</th>
          <th lay-data="{field:'typename'}">申诉类型</th>
          <th lay-data="{field:'cliname'}">客户姓名</th>
          <th lay-data="{field:'content'}">申诉内容</th>
          <th lay-data="{field:'huifu'}">回复内容</th>
          <th lay-data="{field:'adminuser'}">状态</th>
          <th lay-data="{field:'statusname'}">状态</th>
          <th lay-data="{field:'updatedate'}">回复时间</th>
          <th lay-data="{field:'adddate'}">添加时间</th>
          <th lay-data="{field:'linkman'}">联系人</th>
          <th lay-data="{field:'linkphone'}">联系电话</th>
          <th lay-data="{fixed: 'right', width:200, align:'center', toolbar: '#barDemo'}">操作</th>
  </thead>
</table>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="show_image">查看图片</a>
  <a class="layui-btn layui-btn-xs" lay-event="huifu">回复</a>
</script>
{/block}
{block name="script"}
<script type="text/javascript">
  layui.use('table', function(){
    var table = layui.table;
    var $ = layui.$, active = {
      reload: function(){
        var demoReload = $('#demoReload');
        //执行重载
        table.reload('lists', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          ,where: $('#searchForm').serializeObject()
        });
      }
    };
    $('.demoTable .layui-btn').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  layui.use('laydate', function(){
    var laydate = layui.laydate;
    laydate.render({ 
      elem: '#startdate'
      ,type: 'datetime'
      // ,value: "{:date('Y-m-d')}" + " 00:00:00"
    });
    laydate.render({ 
      elem: '#enddate'
      ,type: 'datetime'
      // ,value: "{:date('Y-m-d H:i:s')}"
    });
  });
  function show_image(data) {
    var layindex = layer.open({
      type: 2,
      area: ['800px', '700px'],
      fixed: false, //不固定
      maxmin: true,
      content: APP_URL+"/admin/complaint/image?id="+data.images,
      title:'申诉图片'+data.images,
      shade: [0.8, '#000000']
    });
  }
  function huifu(data) {
    var layindex = layer.open({
      type: 2,
      area: ['700px', '600px'],
      fixed: false, //不固定
      maxmin: true,
      content: APP_URL+"/admin/complaint/adddesc?id="+data.id,
      title:'发货',
      btn: ['确定', '取消'],
      shade: [0.8, '#000000'],
      yes:function(index,layero){
        //parent.$('#parentIframe').text('我被改变了');
        var iframeWin = window[layero.find('iframe')[0]['name']];
        formobj = iframeWin.$("form");
        ajaxUrl = formobj.attr("action");
        if(ajaxUrl == undefined || ajaxUrl == ''){
          ajaxUrl = defaultSaveUrl;
        }
        datajson = formobj.serialize();
        searchMap.postData = datajson;
        console.log(datajson);
        $.post(ajaxUrl,searchMap,function(datajson){
          var serializeObj={};
          if(datajson.status == 1){
            $(formobj.serializeArray()).each(function(){  
              serializeObj[this.name]=this.value;  
            });  
            layer.msg("操作成功",function(){
              layer.closeAll();
            });
            setTimeout(function() {
              location.reload();
            }, 300);
          }
          else{
            layer.msg(datajson.msg);
            return false;
          }
        },'json');
      }
    });
  }
</script>
{/block}